package com.cn.lyl.dao.impl;

import com.cn.lyl.dao.LawyerDao;
import com.cn.lyl.dao.LawyerRoleDao;
import com.cn.lyl.model.LawyerRoleModel;
import com.cn.lyl.util.JDBC;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class LawyerRoleDaoImpl implements LawyerRoleDao {
    @Override
    public int add(LawyerRoleModel LawyerRoleModel) {
        return 0;
    }

    @Override
    public int update(LawyerRoleModel LawyerRoleModel) {
        return 0;
    }

    @Override
    public int delete(LawyerRoleModel LawyerRoleModel) {
        return 0;
    }

    @Override
    public LawyerRoleModel findById(int id) {
        return null;
    }

    @Override
    public LawyerRoleModel findByName(LawyerRoleModel lawyerRoleModel) {
        String sql ="select id from lawyer_role where role ='"+lawyerRoleModel.getRole()+"'";
        ResultSet query = JDBC.query(sql);
        LawyerRoleModel lawyerRoleModel1 = new LawyerRoleModel();
        try{
            if(query.next()){
                lawyerRoleModel1.setId(query.getInt("id"));
                lawyerRoleModel1.setRole(query.getString("role"));
            }
        }catch (Exception e){

        }
        return lawyerRoleModel1;
    }

    @Override
    public List<LawyerRoleModel> findAll() {
        String sql ="select role from lawyer_role";
        ResultSet query = JDBC.query(sql);
        List<LawyerRoleModel> list = new ArrayList<>();
        try {
            while (query.next()) {
                LawyerRoleModel lawyerRoleModel = new LawyerRoleModel();
                lawyerRoleModel.setRole(query.getString("role"));
                list.add(lawyerRoleModel);
            }
        }catch (Exception e){

        }
        return list;
    }
}
